import { createRouter, createWebHashHistory } from 'vue-router';

const routes = [
  {
    name: 'notFound',
    path: '/:path(.*)+',
    redirect: {
      name: 'home',
    },
  },
  {
   name: 'home',
   path: '/home',
   component: () => import('./view/home'),
   meta: {
     title: 'home',
   },
  },
  {
    name: 'prize_area',
    path: '/prize_area',
    component: () => import('./view/prize_area'),
    meta: {
      title: 'botim_prize_area',
    },
  },
  {
    name: 'draws',
    path: '/draws',
    component: () => import('./view/history_draw'),
    meta: {
      title: 'draws',
    },
  },
  {
    name: 'cart',
    path: '/cart',
    component: () => import('./view/draws'),
    meta: {
      title: 'cart',
    },
  },
  {
    name: 'profile',
    path: '/profile',
    component: () => import('./view/me'),
    meta: {
      title: 'profile',
    },
  },
  {
    name: 'purchase_prize',
    path: '/purchase_prize',
    component: () => import('./view/purchase_prize'),
    meta: {
      title: 'purchase_prize',
    },
  },
  {
    name: 'edit_address',
    path: '/edit_address/:context',
    component: () => import('./view/edit_address'),
    meta: {
      title: 'edit_address',
    },
  },
  {
    name: 'address_admin',
    path: '/address_admin',
    component: () => import('./view/address_admin'),
    meta: {
      title: 'address_admin',
    },
  },
  {
    name: 'shipped_information',
    path: '/shipped_information/:context',
    component: () => import('./view/shipped_information'),
    meta: {
      title: 'shipped_information',
    },
  },
  {
    name: 'view_code',
    path: '/view_code/:context',
    component: () => import('./view/view_code'),
    meta: {
      title: 'view_code',
    },
  },
  {
    name: 'win_lottery',
    path: '/win_lottery/:context',
    component: () => import('./view/win_lottery'),
    meta: {
      title: 'win_lottery',
    },
  },
  {
    name: 'cart',
    path: '/cart',
    component: () => import('./view/draws'),
    meta: {
      title: 'Cart',
    },
  },
  {
    name: 'goods',
    path: '/goods/:context',
    component: () => import('./view/goods'),
    meta: {
      title: 'goods',
    },
  },
  {
    name: 'order',
    path: '/order/:context',
    component: () => import('./view/order'),
    meta: {
      title: 'order',
    },
  },
  {
    name: 'pop',
    path: '/pop',
    component: () => import('./view/pop'),
    meta: {
      title: 'pop',
    },
  },
  
];

const router = createRouter({
  routes,
  history: createWebHashHistory(),
});

router.beforeEach((to, from, next) => {
  const title = to.meta && to.meta.title;
  if (title) {
    document.title = title;
  }
  next();
});

export { router };
